var url = ""; //页面请求路径
var token = ""; //标记用户唯一id
var user_id = 0; //用户id
var user_head_portrait_url = ""; //用户头像

//全局后台方法访问路径   http://127.0.0.1:8899/api/consumer/
var path = "http://127.0.0.1:8899/api/consumer/"
//全局图片访问路径    http://120.48.47.144:8899/images/
var imagePath = "http://120.48.47.144:8899/images/"
//视频
var videoPath = "http://120.48.47.144:8899/videos/"

$(document).ready(function() {
	url = location.search;
	if (url.indexOf("//") != -1 && url.substr(url.indexOf("//") + 2).length > 0) { //有token
		token = url.substring(url.indexOf("//") + 2);
	}
});

/* 获取登录用户信息+token */
function get_user_mess_and_token() {
	if (document.cookie != null && document.cookie.length != 0) {
		var all_cookies = document.cookie.split(";");
		for (var i in all_cookies) {
			var this_cookie = all_cookies[i];
			if(this_cookie.split("=")[0].trim() == "cookie_token"){
				token = this_cookie.split("=")[1];
			}
			if (this_cookie.split("=")[0].trim() == "cookie_user") {
				user_mess_and_token = this_cookie.indexOf(";") != -1 ? this_cookie.substring(0, this_cookie.length -
						1) :
					this_cookie.split("=")[1];
				var user = JSON.parse(decodeURIComponent(user_mess_and_token));
				user_id = user.user_id;
				user_head_portrait_url  =user.user_head_portrait_url;
				$("#login_button").hide();
				$("#exit_login").show();
				$("#login_true").show();
				$(".user_head_portrait_url").attr("src", user_head_portrait_url.indexOf("https") != -1 ? //微信登录
					decodeURIComponent(user_head_portrait_url, "utf-8") : "http://120.48.47.144:8899/images/" +
					user_head_portrait_url); // 显示用户头像
				$("#to_my_homepage").attr("href","http://127.0.0.1:8899/html/car_my_homepage.html?"+user_id);
			}
		}
	}
}

/* 退出登录 */
function exit_login() {
	$.post("http://127.0.0.1:8899/api/consumer/UserController/exit_login/" + token, function(data) {
		if (data.result == "true") {
			token = "";
			$("#login_button").show();
			$("#login_true").hide();
			$("#exit_login").hide();
			location.search = url;
		}
	}, "json");
}
